import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/entities/setting_data_entity.dart';
import 'package:finance_app/src/utils/input_formatter_tools.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';

import 'down_button_form.dart';
import 'form_edit_status_inherited_widget.dart';

class IconCurrencyPriceInputForm extends StatelessWidget {
  final String svgIconPath;
  final String currency;
  final TextEditingController controller;
  final FocusNode focusNode;
  final VoidCallback onChangeCurrency;
  final double leftPadding;
  final double rightPadding;
  final bool enable;

  const IconCurrencyPriceInputForm(
      {Key key,
      this.svgIconPath,
      this.currency,
      this.controller,
      this.focusNode,
      this.onChangeCurrency,
      this.leftPadding,
      this.rightPadding,
      this.enable = true})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget child = Builder(
        builder: (BuildContext context) => Container(
              decoration: BoxDecoration(
                  border: Border(
                      bottom: BorderSide(
                    color: aceGrayColor,
                    width: getDp(0.5),
                  )),
                  color: Colors.white),
              padding: EdgeInsets.only(
                left: leftPadding ?? getDp(35),
                right: rightPadding ?? getDp(35),
                top: getDp(10),
                bottom: getDp(10),
              ),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  if (svgIconPath != null)
                    SvgPicture.asset(
                      svgIconPath,
                      width: getDp(22),
                      height: getDp(22),
                      fit: BoxFit.contain,
                    ),
                  DownButtonForm(
                    title: currency,
                    onTap: onChangeCurrency,
                  ),
                  Expanded(
                    child: FormStatusWidget(
                      builder: (enable) => TextField(
                        scrollPadding: EdgeInsets.zero,
                        decoration: InputDecoration(
                            contentPadding: EdgeInsets.zero,
                            border: InputBorder.none,
                            hintText: '0.00',
                            hintStyle: TextStyle(
                              color: aceGrayColor,
                              fontSize: getSp(24),
                              fontWeight: FontWeight.w700,
                              height: 24 / 24,
                            )),
                        inputFormatters: [
                          doubleInputFormatter,
                        ],
                        keyboardType:
                            TextInputType.numberWithOptions(decimal: true),
                        style: TextStyle(
                          color: enable ? aceBlueColor : aceBlackColor,
                          fontSize: getSp(24),
                          fontWeight: FontWeight.w700,
                          height: 24 / 24,
                        ),
                        enabled: enable,
                        controller: controller,
                        focusNode: focusNode,
                      ),
                    ),
                  ),
                ],
              ),
            ));
    if (enable == false) {
      child = FormEditStatusInheritedWidget(
        isEdit: false,
        child: child,
      );
    }
    return child;
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(DoubleProperty('leftPadding', leftPadding));
    properties.add(DoubleProperty('rightPadding', rightPadding));
    properties.add(ObjectFlagProperty<VoidCallback>.has(
        'onChangeCurrency', onChangeCurrency));
    properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode));
    properties.add(
        DiagnosticsProperty<TextEditingController>('controller', controller));
    properties.add(StringProperty('currency', currency));
    properties.add(StringProperty('svgIconPath', svgIconPath));
  }
}
